package TEST0813;

import java.util.Scanner;

public class Number3 {
    static final long MOD = (long) (10e9+7L);

    static long modPow(long a,long e){
        long r=1%MOD;
        a%=MOD;
        while(e>0){
            if((e&1)==1){
                r=(r*a)%MOD;
            }
            a=(a*a)%MOD;
            e>>=1;
        }
        return r;
    }

    static long combBigN(long N,int k,long[]fac,long[]ifac){
        if(k<0)return 0;
        if(k==0) return 1;
        long num=1;
        for(int i=1;i<=k;i++){
            num=(num*((N-i+1)%MOD))%MOD;
        }
        return (num*ifac[k]%MOD);
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long[]a=new long[n];
        for(int i=0;i<n;i++) {
            a[i]=sc.nextLong();
        }

        int totalZero=0;
        for(long v:a){
            if(v==0) totalZero++;
        }

        long[]fac=new long[totalZero+1];
        long[]ifac=new long[totalZero+1];
        fac[0]=1;
        for(int i=1;i<=totalZero;i++){
            fac[i]=fac[i-1]*i%MOD;
        }
        ifac[totalZero]=modPow(fac[totalZero],MOD-2);
        for(int i=totalZero;i>0;i--){
            ifac[i-1]=ifac[i]*i%MOD;
        }
        long ans=1;
        long L=a[0];
        int t=0;

        for (int i=1;i<n;i++){
            if(a[i]==0){
                t++;
            }else {
                long R =a[i];
                if(t>0){
                    long N = (R-L)+t;
                    ans=ans*combBigN(N,t,fac,ifac)%MOD;
                    t=0;
                }
                L=R;
            }
        }
        System.out.println(ans%MOD);
    }
}
